<?php
  class UserLogin
  {                                          
      private $UserId;
      private $User;
      private $ingelogd = false;
     
      public function __construct()
      {
          if($_SESSION['ingelogd'] == true && isset($_SESSION['userid']))
         {
             $this->ingelogd = true;
             $this->UserId = $_SESSION['userid']; 
             $this->User = GebruikerPeer::retrieveByPK($this->UserId);  
         }  
          
      }
      
      public function login($user,$pass)
      {
         if( $user = GebruikerPeer::login($user,$pass))
         {
              $this->ingelogd = true;                                              
              $this->UserId = $user->getGebruikerid(); 
              $_SESSION['ingelogd'] = true;
              $_SESSION['userid'] = $this->UserId;
              header("Location: home");  
         }
         else
         {
             throw new LoginException('Gebruikersnaam of wachtwoord klopt niet!');    
         }
         
      }
      
      public function loguit()
      {
          session_destroy();
          header("Location: ".core::$config['full_url']."0/home");
      }
      
      public function is_ingelogd()
      {
         return $this->ingelogd;    
      }
      
      public function getUser()
      {
          return $this->User;
      }
      
      static function doEncryptPass($name, $pass) 
      {
        $password = str_split($pass,strlen($pass)/2+1);
        $hash = hash('whirlpool', $name.$password[0].'centerSalt'.$password[1]);
        return $hash;
      }
      
  }
?>